<?php
namespace app\base\model;
use app\base\CommonModel;
class Cart extends CommonModel {
  public function __construct($data = [])
  {
      parent::__construct($data);
  }
  /**
   *购物车列表
   */
  public function cartList($user_id,$type){
      $where['c.user_id']=$user_id;
      if($type==1){
          $where['c.is_less_price']=1;
      }
      $list=$this->alias('c')
           ->join('yc_goods g','c.goods_id=g.goods_id','left')
           ->join('yc_goods_attr_combination ga','c.com_id=ga.com_id','left')
           ->field('c.cart_id,c.user_id,c.com_id,c.goods_num,c.goods_price,c.goods_total_price,c.is_less_price,g.goods_id,g.goods_name,g.goods_thumb,g.goods_desc,g.goods_original_price,ga.original_price')
           ->where($where)
           ->order('c.cart_id','desc')
           ->select();
      $less_count=0;
      foreach($list as $key=>$value){
          if($value['is_less_price']==1){
                  $less_count+=1;
          }
          if($value['com_id']==0){
              $list[$key]['original_price']=$value['goods_original_price'];
          }else{
              $list[$key]['original_price']=$value['original_price'];
          }
          unset($value['goods_original_price']);
      }
      $result['list']=$list;
      $result['less_count']=$less_count;
      return $result;
  }



}